% IIF 
% Instantaneously-cued Interleaved Fixed-gap
%
% a statewait task for the eyelink with no error feedback
clc; 
clear;
close all;

cd C:\_bcoe\Data_Eyelink2\;
try % this should speed things along if your running a few studies on the same subject
    load('temp')
    for par = 1:size(Parameters,1)% assign each parameter in the table to its value
        eval([Parameters{par,1} '=''' Parameters{par,2} ''';']); % for string entries
    end   
    if ~strcmp(kyou,standard_date(2))% check if it exists & ...
        error;% if today's date doesn't match the date in the temp file force 'try' to fail
    end   
    file_nb=str2num(file_nb)+1;% check if it exists & increment
    task;
    pro_color;
catch
    beep
    sub_inits='ABC';
    kyou=standard_date(2);
    file_nb='00';    
    task='3';
    pro_color='1';
    Parameters={... % variable  value           'discription'                           string or number?
            'sub_inits',	sub_inits,		'Subjects 3 Initials [ABC]',                        's';...
            'kyou',		    kyou,		    'Today''s Date [yyyy-mm-dd]',                       's';...
            'file_nb',		file_nb,		'File # [or run #, always 2 digits]:',              's';...
            'task',	        task,	        'Which Task: 1)IIR, 2)IIF, 3)PIF',                   'n';...
            'pro_color',	pro_color, 	    'Color assignment: 1)Pro=Orange or 2)Anti=Orange',  'n';...
        };    
    save('temp','Parameters');    % saves temp data (still in string format)
end
update=1;
info=0;
while update
    [ParamInputs update] = inputdlg_offscreen(Parameters(:,3), 'Enter Parameters', 1, Parameters(:,2));
    if isempty(ParamInputs);
        disp('Task Canceled');
        return
    end
    [Parameters{:,2}] = deal(ParamInputs{:});
    save('temp','Parameters');    % saves temp data (still in string format)
    for par= 1:length(Parameters) 
        eval([Parameters{par,1} '=''' Parameters{par,2} ''';']); 
    end
    if length(sub_inits)>3 | length(sub_inits)<3  %check sub_inits
        Parameters(strcmp(Parameters,'sub_inits'),2)={'ABC'};
        update=1;
    end   
    if length(file_nb)>2 | length(file_nb)<2 %check file_nb
        Parameters(strcmp(Parameters,'file_nb'),2)={'00'};
        update=1;
    end

    kyou=standard_date(2);
    Parameters(strcmp(Parameters,'kyou'),2)={kyou}; %force this one

    if isempty(find(pro_color(1)=='12')) | length(pro_color)>1 %check pro_color
        Parameters(strcmp(Parameters,'pro_color'),2)={'1'};
        update=1;
    end
    if isempty(find(task(1)=='123'))| length(task)>1 | update>0 %check task last then go.
        Parameters(strcmp(Parameters,'task'),2)={'1'};
        update=1;
    else
        switch str2num(task)
            case 1           
                cd IIR;cd
                info=IIR_may_09(Parameters);
            case 2
                cd IIF;cd
                info=IIF_may_09(Parameters);
            case 3
                cd PIF;cd
                info=PIF_may_09(Parameters);
        end
    end
    if info
        update=1;
    end
end%while update
dir
cd C:\_bcoe\Data_Eyelink2\;
return
